package com.woniu.p2p.controller;

import com.github.pagehelper.PageInfo;
import com.woniu.p2p.entity.UserMessage;
import com.woniu.p2p.service.P2PMessageService;
import com.woniu.p2p.vo.FindMessageVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @author 86152
 * @create 2020/8/10
 * @since 1.0.0
 */
@RestController
@RequestMapping("/message")
public class P2PMessageController {

    @Autowired
    P2PMessageService p2PMessageService;

    /*获取信息*/
    @RequestMapping("/findmessagelist")
    public PageInfo<UserMessage> findmessagelist(HttpServletRequest request){
        String token = request.getHeader("token");
        int userid = Integer.parseInt(token);
        int start=1;
        int size=4;
        PageInfo<UserMessage> userMessagePageInfo=p2PMessageService.findAll(start,size,userid);
        return userMessagePageInfo;
    }

    /*根据页码获取信息*/
    @RequestMapping("/findsinglemessagepage")
    public PageInfo<UserMessage> findsinglemessagepage(@RequestBody FindMessageVo findMessageVo, HttpServletRequest request){
        String token = request.getHeader("token");
        int userid = Integer.parseInt(token);
        Integer pageNum = findMessageVo.getPageNum();
        Integer pageSize = findMessageVo.getPageSize();
        PageInfo<UserMessage> userMessagePageInfo = p2PMessageService.findAll(pageNum, pageSize, userid);
        return userMessagePageInfo;
    }
}
